<template>
  <Modal v-model="show" width="600" title="新增供稿单位" @on-cancel="close">
    <ProvideUnitForm ref="provideUnit_ref" :form-data="formData" @on-theme-submit="handleThemeSubmit"></ProvideUnitForm>

    <template #footer>
      <div class="text-center mt10 mb12">
        <Button class="ivu-btn--round ml14" @click="close">取消</Button>
        <Button class="ivu-btn--round" type="primary" @click="handleSave">保存</Button>
      </div>
    </template>
  </Modal>
</template>

<script>
import ProvideUnitForm from './ProvideUnitForm.vue'

// util
import { handleRequestStatus } from '@/utils/uitls.js'
const createForm = () => ({ name: '', produceNum: 0 })

// request
import { systemOrganAdd } from '@/api/system/organConfig.js'
export default {
  name: 'ProvideUnitCreate',

  components: { ProvideUnitForm },

  props: {
    visible: Boolean,
  },

  data() {
    return {
      formData: createForm(),
    }
  },

  computed: {
    show: {
      get() {
        return this.visible
      },
      set(v) {
        this.$emit('update:visible', v)
      },
    },
  },

  methods: {
    close() {
      this.show = false
      this.$nextTick(() => {
        this.formData = createForm()
      })
    },

    handleSave() {
      this.$refs['provideUnit_ref'].handleFormSubmit()
    },

    handleThemeSubmit(data) {
      this.systemOrganAdd(data)
    },

    async systemOrganAdd(data) {
      const res = await systemOrganAdd(data)
      handleRequestStatus(res, '新增', () => {
        this.$emit('on-add-success')
        this.close()
      })
    },
  },
}
</script>

<style lang="less" scoped></style>
